Skip to content

Fix inset locator renderer fallback (swev-id: matplotlib__matplotlib-26291)#69

Open
casey-brooks wants to merge 2 commits intomatplotlib__matplotlib-26291from
fix/inset_axes-renderer-none
Open

Fix inset locator renderer fallback (swev-id: matplotlib__matplotlib-26291)#69
casey-brooks wants to merge 2 commits intomatplotlib__matplotlib-26291from
fix/inset_axes-renderer-none

Conversation

@casey-brooks
Copy link

Summary

  • ensure AnchoredLocatorBase.__call__ acquires a renderer if one was not provided
  • prevent AttributeError when inline backend implicitly requests bbox_inches='tight'
  • keep existing locator behavior otherwise unchanged

Observed Failure

  • AttributeError: 'NoneType' object has no attribute '_get_renderer' when inset_axes is used under the inline backend with tight bounding box rendering

Reproduction

  1. Run the inline smoketest snippet from Issue [Bug] inset_axes fails under inline backend with bbox_inches=tight (renderer None) #67 to see the AttributeError
  2. With this branch, rerun the same snippet and verify it completes and saves the figure
  3. Confirm Axes.inset_axes still works with bbox_inches='tight'

Fixes #67

@casey-brooks casey-brooks requested a review from a team December 25, 2025 13:18
@casey-brooks
Copy link
Author

Test & Lint Summary

LD_LIBRARY_PATH=/root/.nix-profile/lib:/nix/store/qipd93x9gjyiygqk673rd2ssnf8y7jj0-gcc-14.3.0-lib/lib:/nix/store/f8w1i7yisixb9hivzbk0l4ixmf67fjqr-gcc-14.3.0-libgcc/lib:$LD_LIBRARY_PATH MPLBACKEND=Agg .venv/bin/python - <<'PY'
import matplotlib
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
fig, (ax, ax2) = plt.subplots(1, 2, figsize=(5.5, 2.8))
axins = inset_axes(ax, width=1.3, height=0.9)
fig.savefig('out.png', bbox_inches='tight')
print('smoketest1 ok')
PY
→ passed

LD_LIBRARY_PATH=/root/.nix-profile/lib:/nix/store/qipd93x9gjyiygqk673rd2ssnf8y7jj0-gcc-14.3.0-lib/lib:/nix/store/f8w1i7yisixb9hivzbk0l4ixmf67fjqr-gcc-14.3.0-libgcc/lib:$LD_LIBRARY_PATH MPLBACKEND=Agg .venv/bin/python - <<'PY'
import matplotlib
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
axins = ax.inset_axes([0.6, 0.6, 0.3, 0.3])
fig.savefig('axes_inset.png', bbox_inches='tight')
print('smoketest2 ok')
PY
→ passed

.venv/bin/flake8 lib/mpl_toolkits/axes_grid1/inset_locator.py
→ no issues

Copy link

@noa-lucent noa-lucent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing the renderer hand-off. We still need a regression test to make sure the inline backend + bbox_inches='tight' path is covered.

@casey-brooks
Copy link
Author

Added covering the inline tight-bbox path. Verified locally with:

The test passed.

Copy link

@noa-lucent noa-lucent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regression smoketest looks good; thanks for adding it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants